<?php
	session_start(); //因为sidebar.php 存在session_start(); 本页面若不再包含sidebar.php 则不能注销此句
	include_once("conn.php");

	$board_name = $_POST["hide_board_name"];     //所要发布帖子的版面
	$post_er = $_SESSION["current_user"];          //发表人显然必须为当前登录用户

	$post_name = $_POST["new_title"];			//帖子名
	$post_content = $_POST["new_content"];		//帖子内容

	//因为要插入帖子的数据库必须要有，t_sid,t_uid,但是我只有版面name和用户name,没有版面id和用户id，所以先SQL取出2个ID。
	$sql = "select * from bbs_user where u_name = '".$post_er."'";
	$result = mysql_query($sql);
	$q_result = mysql_fetch_array($result);
	$post_er_uid = $q_result["u_id"];                     //取的的用户id

	$sql = "select * from bbs_session where s_name = '".$board_name."'";
	$result = mysql_query($sql);
	$q_result = mysql_fetch_array($result);
	$board_id = $q_result["s_id"];						//取得的版面id
	
	date_default_timezone_set("PRC");
	$post_time = date("Y-m-d H:i:s",time());			//发表帖子的时间

	$sql = "insert into bbs_topic(t_sid,t_uid,t_topic,t_content,t_time,t_author,t_last_reply_name,t_session_name) values('".$board_id."','".$post_er_uid."','".$post_name."','".$post_content."','".$post_time."','".$post_er."','".$post_er."','".$board_name."')";
	
	$result = mysql_query($sql);

?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html" charset=utf-8 />
</head>
<body>
<div class = "body">
	
<?php 
	if($result)
	{	/*
		$sql2 = "select * from bbs_session where s_name = '".$board_name."'";
		$result2 = mysql_query($sql2);
		$q_result2 = mysql_fetch_array($result2);
		$s_topic_num = $q_result2["s_topic_num"];		//取得版面的帖子总数，但多用户时我想可能会出错，因为同时取这个数的话是相等的。
		
		$s_topic_num = $s_topic_num+1;					//result为1证明帖子发表成功，版面帖子总数+1;

		$sql2 = "update bbs_session set s_topic_num = '".$s_topic_num."' where s_name = '".$board_name."'";
		mysql_query($sql2);                 //仅实现发新帖时候 帖总量+1
		*/

		echo "<script>alert('发表成功');</script>";
		$page = "page.php?board=".$board_name."";
		echo "<script>window.location = '".$page."'</script>";
	}
	else {
		echo "发表失败";
	}
?>

<p><strong><a href = "page.php?board=<?php echo $board_name; ?>">点此跳转回浏览版面</a></strong></p>

</div>

</body>
</html>
